package com.lxx.train.${module}.controller;

import com.lxx.train.common.resp.CommonResp;
import com.lxx.train.common.resp.PageResp;
import com.lxx.train.${module}.req.${Domain}QueryReq;
import com.lxx.train.${module}.req.${Domain}SaveReq;
import com.lxx.train.${module}.resp.${Domain}QueryResp;
import com.lxx.train.${module}.service.${Domain}Service;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/${do_main}")
public class ${Domain}Controller {

    @Autowired
    private ${Domain}Service ${domain}Service;

    // 新增 / 更新
    // 判断前端有无传id，没有则是新增，否则是更新
    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody ${Domain}SaveReq req) {
        ${domain}Service.save(req);
        return CommonResp.ok();
    }

    // 查询列表
    @GetMapping("/query-list")
    public CommonResp<PageResp<${Domain}QueryResp>> queryList(@Valid ${Domain}QueryReq req) {
        PageResp<${Domain}QueryResp> pageResp = ${domain}Service.queryList(req);
        return CommonResp.ok(pageResp);
    }

    // 删除
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        ${domain}Service.delete(id);
        return CommonResp.ok();
    }

}
